package phidgetmotion.gui;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;

import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.WindowConstants;

import com.phidgets.PhidgetException;

import phidgetmotion.phidget.Accelerometer;

public class PhidgetMotionFrame extends JFrame {
	private static final long serialVersionUID = -1748991551694480074L;

	private WindowAdapter exitListener = new WindowAdapter()
	{
		@Override
		public void windowClosing(WindowEvent e)
		{
			try {
				Accelerometer.close();
			} catch (PhidgetException e1) {
				e1.printStackTrace();
			}
		}
		
	};

	public PhidgetMotionFrame(File modelFile) {
		JTabbedPane tabbedPane = new JTabbedPane();
		tabbedPane.addTab("Train", new TrainPanel(modelFile));
		tabbedPane.addTab("Test", new TestPanel());
		tabbedPane.addTab("Evaluate",  new EvaluatePanel());

		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(tabbedPane, BorderLayout.CENTER);
		getContentPane().add(new StatusBar(), BorderLayout.SOUTH);

		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		addWindowListener(exitListener);
		pack();
	}
}
